<template>
	<view>
		<view class="jump-page">
			<image class="wx-img" src="../../static/img/wx_img.png" mode=""></image>
			<view>
				平台网络服务自动跳转微信授权中...
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return{
				code: '',
				appId: ''
			}
		},
		onLoad(option){
			this.code = option.code
			this.appId = option.appId
			this.loginByWechat()
		},
		methods:{
			async loginByWechat() {
				let link = window.location.href;
				if (link.includes("com/?code")) {
					if (link.includes("homeWxAuth?appId")) {
						var url = link.split('state=STATE/')
						var appId = url[1].split('?appId=')[1]
						var urlLeft = url[0].split('com/')[0]
						var urlCenter = url[1].split('?appId=')[0]
						var urlRight = url[0].split('com/')[1]
						var newUrl = urlLeft + 'com/' + urlCenter + urlRight + 'state=STATE&appId=' + appId
						window.location.href = newUrl;//拼接跳转
					}
				}
				if (this.code) {
					uni.request({
						url:this.GLOBAL.BASE_URL+'baseapi/push/bindWeChatOfficialAccount',
						method:'get',
					    data:{
						    token: uni.getStorageSync('token'),
							appId: this.appId,
							code: this.code
					    },success:res=>{
							this.$msg.showToast(res.data.msg)
							setTimeout(()=>{
								uni.switchTab({
									url: '../home/home'
								})
							},1000)
					    }
					})
				}
			
			},
			isWechat () {
				return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
			}
		}
	}
</script>

<style scoped lang="less">
	.jump-page {
		text-align: center;
		.wx-img {
			width: 90px;
			height: 90px;
			margin-top: 40%;
		}
	}
	
</style>

